package com.kis.pattern.mediator;

/**
 * Created by yks on 15-11-17.
 */
public class MotherBoard implements Mediator {
    private CDDriver cdDriver = null;
    private CPU cpu = null;
    private SoundCar soundCar = null;
    private VideoCard videoCard = null;

    public void setCdDriver(CDDriver cdDriver) {
        this.cdDriver = cdDriver;
    }

    public void setCpu(CPU cpu) {
        this.cpu = cpu;
    }

    public void setSoundCar(SoundCar soundCar) {
        this.soundCar = soundCar;
    }

    public void setVideoCard(VideoCard videoCard) {
        this.videoCard = videoCard;
    }

    @Override
    public void changed(Colleague colleague) {
        if (colleague == cdDriver) {
            this.opCd((CDDriver) colleague);
        } else if (colleague == cpu) {
            this.opeCpu((CPU) colleague);
        }
    }

    private void opCd(CDDriver cdDriver) {
        String data = cdDriver.getData();
        this.cpu.executeData(data);
    }

    private void opeCpu(CPU cpu) {
        String v = cpu.getVideoData();
        String s = cpu.getSoundData();
        this.videoCard.showData(v);
        this.soundCar.soundData(s);
    }
}
